// 花名册Api
import request from '@/utils/request'
import requestFile from '@/utils/request-file'
import { formatDateByFmt } from '@/utils/util'
import qs from 'qs'

const prefixUrl = 'web/roster/'

export function list(params) {
  return request({
    url: prefixUrl + 'list',
    method: 'get',
    params,
    paramsSerializer: params => {
      return qs.stringify(params, {
        indices: false
      })
    }
  })
}

export function detail(params) {
  return request({
    url: prefixUrl + 'detail',
    method: 'get',
    params
  })
}

// 导出员工信息
export function export_excel(params) {
  return requestFile({
    url: prefixUrl + '/export_excel',
    method: 'get',
    params,
    fileName: '花名册' + (formatDateByFmt(new Date(), 'yyyyMMddhhmmss') + Math.floor(Math.random() * (
      1000000 -
      1) + 1)) + '.xlsx'
  })
}

export function list_regular_user(params) {
  return request({
    url: prefixUrl + 'list_regular_user',
    method: 'get',
    params
  })
}

// 验证手机号
export function verifyMobile(params) {
  return request({
    url: prefixUrl + 'verifyMobile',
    method: 'post',
    params
  })
}

// 查询用户关联的手机号
export function queryUserMobile(params) {
  return request({
    url: prefixUrl + 'queryUserMobile',
    method: 'get',
    params
  })
}

// 保存或修改
export function addOrEdit(data) {
  return request({
    url: prefixUrl + 'addOrEdit',
    method: 'post',
    content_type: 'json',
    data
  })
}

// 删除手机号
export function removeMobile(params) {
  return request({
    url: prefixUrl + 'removeMobile',
    method: 'post',
    params
  })
}
